import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: HP
 * Date: 2023 -04 -29
 * Time: 22:30
 */
class GeoArrayList {
    private ArrayList<Shape> list = new ArrayList<Shape>();

    public GeoArrayList() {
    }

    public GeoArrayList(ArrayList<Shape> list) {
        this.list = list;
        Collections.sort(this.list, new Comparator<Shape>() {
            @Override
            public int compare(Shape o1, Shape o2) {
                if (o1.getArea() > o2.getArea())
                    return 1;
                else if (o1.getArea() < o2.getArea())
                    return -1;
                else
                    return 0;
            }
        });
    }

    public void insertGeoShape(Shape s) {
        list.add(s);
        Collections.sort(list, new Comparator<Shape>() {
            @Override
            public int compare(Shape o1, Shape o2) {
                if (o1.getArea() > o2.getArea())
                    return 1;
                else if (o1.getArea() < o2.getArea())
                    return -1;
                else
                    return 0;
            }
        });
    }

    public void remove(Shape s) {
        list.remove(s);
    }


    public int getIndex(Shape s) {
        return list.indexOf(s);
    }

    public Shape get(int index) {
        return list.get(index);
    }

    public int size() {
        return list.size();
    }

    public void clear() {
        list.clear();
    }

    public boolean contains(Shape s) {
        return list.contains(s);
    }

    public void displayGeoList() {
        for (int i = 0; i < list.size(); i++) {
            System.out.println("Area of " + list.get(i).getClass().getSimpleName() + " " + (i + 1) + ": " + list.get(i).getArea());
        }
    }
}